<?php
/**
 * Created by lzl
 * Date: 2021 2021/10/9
 * Time: 13:07
 */
namespace App\Services\Api;
use App\Exceptions\RequestException;
use App\Forms\ConfigForms;
use App\Forms\PluginForms;
use App\Plugins\Forms\ShareFreeForms;
use App\Plugins\Services\Api\ShareFreeOrderServices;
use App\Services\BaseServices as Base;


class PluginServices extends Base
{


    /**
     * @return array
     */
    public function getHomePlugin()
    {
        //分享免费拿
        $is_share_free = (new ConfigForms())->getDetail('is_share_free');

        $plugin = (new PluginForms())->getDetail('share_free');

        if($is_share_free->value && $plugin->status){

            $share_goods = (new ShareFreeForms())->getShareGoodsList();

            return compact('share_goods');
        }

        return [];

    }


    /**
     * @param $source
     * @return ShareFreeOrderServices
     * @throws RequestException
     */
    public function orderPlugin($source)
    {
        switch ($source){
            case 'share_free':
                return new ShareFreeOrderServices();
            default:
                throw new RequestException('未知插件');
        }
    }

}